<?php
require_once 'pages/TMSItemCreationPage.inc';
require_once 'patcher/TPatcher.inc';

class TMSDeliveryInstallationPage extends TMSItemCreationPage {
	public function http_Install($name,TFile $patch){
		$installed = false;
		try {
			$p = new TPatcher('delivery_installer',$this,$this->Application());
			$p->PrivateDir = $this->Service()->TargetAppPrivateDir;
			$p->AppDir = $this->Service()->TargetAppDir;
			if ($info = $p->ApplyPatch($patch)){
				$this->Model->CreateItem(array('Code'=>$info['Code'],'Name'=>$name,'Component'=>$info['Component'],'Setup'=>$info['Setup']));
				$installed = true;
			}
		} catch (Exception $e){
			throw new TExposableException(_i($e->getMessage()));
		}
		if (!$installed)
			throw new TExposableException('Installation failed!');		
	}
}